package org.theta.framework.core.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.theta.framework.core.lang.AppException;
import org.theta.framework.core.lang.ErrorCode;

public abstract class DateUtils {

	public static final String FORMAT_NORMAL = "yyyy-MM-dd HH:mm:ss.S";

	public static Date now() {
		return new Date();
	}

	public static String format(Date date, String pattern) {
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(date);
	}

	public static Date parse(String dateStr, String pattern) {
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		Date date;
		try {
			date = sdf.parse(dateStr);
		} catch (ParseException e) {
			throw new AppException(ErrorCode.ERROR_SYSTEM, "Exception in date format parsing.", e);
		}
		return date;
	}

}
